package edu.vt.cbil.input;

import edu.vt.cbil.dataset.ConfigObject;
import edu.vt.cbil.dataset.SNPInfo;
import edu.vt.cbil.dataset.RawData;

import java.io.*;
import java.util.ArrayList;

/**
 * Created by SunMing on 2016/6/20.
 */
public class ReadData {
    private String line=null;
    private int i=0;

    public void read(ConfigObject conf,ArrayList<SNPInfo> snpInfos,ArrayList<RawData> rawDatas){
        try {
            File infile = new File(conf.getSAICInputPath() + conf.getChrName());
            InputStreamReader isr = new InputStreamReader(new FileInputStream(infile));
            BufferedReader br=new BufferedReader(isr);

            while ((line=br.readLine())!=null){
                String[] item=line.split("\t");
                String chrName=item[0];
                String snpName=item[1];
                int pos=Integer.parseInt(item[2]);
                double[] data=new double[item.length-3];
                for(int j=0;j<item.length-3;j++){
                    data[j]=Double.parseDouble(item[j + 3]);
                }

                SNPInfo tempSNPInfo=new SNPInfo();
                RawData tempRawData=new RawData();

                tempSNPInfo.setId(i);
                tempSNPInfo.setChrName(chrName);
                tempSNPInfo.setSNPName(snpName);
                tempSNPInfo.setPos(pos);

                tempRawData.setId(i);
                tempRawData.setData(data);

                snpInfos.add(tempSNPInfo);
                rawDatas.add(tempRawData);
            }
            br.close();
            isr.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
